<?php
namespace app\run\controller;

use app\common\controller\Run;

class Task extends Run
{
    /**
    * 初始化 需要调父级方法
    */
    public function initialize()
    {
        //后台中允许不登录操作的方法
        //helper('Auth')->allow(['apigettask']);
        call_user_func(['parent', __FUNCTION__]); 
    }
    
    /**
    * 列表 
    */
    public function lists()
    {
        // 搜索字段
        $this->local['filter'] = [
            'taskname',
            'jobdo',
            'jobtype',
           // 'tasktgroup_id',
        ];
        
        // 列表字段
        $this->local['list_fields'] = [
            'id',
            'taskname',
            'jobdo',
            'jobtype',
            'tasktgroup_id',
            'imggroup_id',
            'wxchatgroup',
            'pyq',
            'addnum',
            'strattime',
            'stoptime'
            // 其他列表字段
        ];
        
        // 添加额外条件
        //$this->local['where'][] = ['字段', '=', '值'];        
        $this->local['order']['id'] = 'ASC';
        call_user_func(['parent', __FUNCTION__]);
    }
    
    /**
    * 添加
    */
    public function create()
    {   // 设置默认值
        //$this->assignDefault('字段名', '默认值');
        // 字段白名单
        //$this->local['whiteList'] = ['id', 'title', ...允许添加的字段列表];   
        call_user_func(['parent', __FUNCTION__]);
    }
    
    /**
    * 修改
    */
    public function modify()
    {   
        // 字段白名单
        //$this->local['whiteList'] = ['id', 'title', ...允许修改的字段列表];
        $id=$this->args['id'];
        $data   = $this->mdl
            ->where('id',$id)
            ->field('jobtype')
            ->find();
        $jobtype=$data['jobtype'];
        if($jobtype=='1'){
            $this->assignDefault('jobdo', '2');
            $this->mdl->form['pyq']['elem']  =0;
            $this->mdl->form['addnum']['elem']  =0;
            $this->mdl->form['addnum']['elem']  =0;
            $this->mdl->form['imggroup_id']['elem']  =0;
            $this->mdl->form['jobtype']['elem']  ='format';
            $this->mdl->form['jobdo']['options'] =[
               // '0' => '加好友',
              //  '1' => '发朋友圈',
                '2' => '邀请入群'
            ];
        }elseif($jobtype=='0'){
            $this->mdl->form['wxchatgroup']['elem']  =0;
            $this->mdl->form['jobtype']['elem']  ='format';
            $this->mdl->form['jobdo']['options'] =[
                 '0' => '加好友',
                '1' => '文字朋友圈',
               // '2' => '邀请入群',
                '3' => '图文朋友圈',
            ];
        }
        call_user_func(['parent', __FUNCTION__]);
    } 
    
    /**
    * 删除
    */
    public function delete()
    {   
        // 设置额外的删除条件
        //$this->local['where'][] = ['is_verify', '=', 0];
        call_user_func(['parent', __FUNCTION__]);
    }  
}
